package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Comment;
import cn.wolfcode.trip.base.service.ICommentService;
import cn.wolfcode.trip.base.util.JasonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 评论的接口
 */
@RestController
@RequestMapping("/comments")
public class CommentController {
    @Autowired
    private ICommentService commentService ;


    /**
     * 新增一条评论
     * 参数：当前评论的用户，当前被评论的事物，事物的类型，当前事物的id，评论的时间，评论的内容
     * 资源：/comments
     * 动作:POST
     */
    @PostMapping
    public Object saveComment(Comment comment){
        JasonResult jr = new JasonResult();

        try {
            commentService.save(comment);
            jr.setData(comment);
        } catch (Exception e) {
            e.printStackTrace();
            jr.mark(e.getMessage());
        }
        return jr ;
    }
}
